home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / app / tools.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-16  |  36.5 KB  |  1,767 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include <glib.h>
  22.  
  23. #include "apptypes.h"
  24.  
  25. #include "appenv.h"
  26. #include "airbrush.h"
  27. #include "bezier_select.h"
  28. #include "blend.h"
  29. #include "brightness_contrast.h"
  30. #include "bucket_fill.h"
  31. #include "by_color_select.h"
  32. #include "clone.h"
  33. #include "color_balance.h"
  34. #include "color_picker.h"
  35. #include "context_manager.h"
  36. #include "convolve.h"
  37. #include "crop.h"
  38. #include "curves.h"
  39. #include "dodgeburn.h"
  40. #include "eraser.h"
  41. #include "gdisplay.h"
  42. #include "gimpdnd.h"
  43. #include "gimpui.h"
  44. #include "hue_saturation.h"
  45. #include "ellipse_select.h"
  46. #include "flip_tool.h"
  47. #include "free_select.h"
  48. #include "fuzzy_select.h"
  49. #include "histogram_tool.h"
  50. #include "ink.h"
  51. #include "iscissors.h"
  52. #include "levels.h"
  53. #include "magnify.h"
  54. #include "measure.h"
  55. #include "move.h"
  56. #include "paintbrush.h"
  57. /* #include "path_tool.h" */
  58. #include "pencil.h"
  59. #include "posterize.h"
  60. #include "rect_select.h"
  61. #include "session.h"
  62. #include "smudge.h"
  63. /* #include "xinput_airbrush.h" */
  64. #include "text_tool.h"
  65. #include "threshold.h"
  66. #include "tools.h"
  67. #include "transform_tool.h"
  68. #include "dialog_handler.h"
  69.  
  70. #include "libgimp/gimpintl.h"
  71.  
  72. #include "pixmaps2.h"
  73.  
  74. #include "cursors/rect_select_small.xbm"
  75. #include "cursors/rect_select_small_mask.xbm"
  76. #include "cursors/ellipse_select_small.xbm"
  77. #include "cursors/ellipse_select_small_mask.xbm"
  78. #include "cursors/free_select_small.xbm"
  79. #include "cursors/free_select_small_mask.xbm"
  80. #include "cursors/fuzzy_select_small.xbm"
  81. #include "cursors/fuzzy_select_small_mask.xbm"
  82. #include "cursors/bezier_select_small.xbm"
  83. #include "cursors/bezier_select_small_mask.xbm"
  84. #include "cursors/scissors_small.xbm"
  85. #include "cursors/scissors_small_mask.xbm"
  86. #include "cursors/move_small.xbm"
  87. #include "cursors/move_small_mask.xbm"
  88. #include "cursors/zoom_small.xbm"
  89. #include "cursors/zoom_small_mask.xbm"
  90. #include "cursors/crop_small.xbm"
  91. #include "cursors/crop_small_mask.xbm"
  92. #include "cursors/resize_small.xbm"
  93. #include "cursors/resize_small_mask.xbm"
  94. #include "cursors/rotate_small.xbm"
  95. #include "cursors/rotate_small_mask.xbm"
  96. #include "cursors/shear_small.xbm"
  97. #include "cursors/shear_small_mask.xbm"
  98. #include "cursors/perspective_small.xbm"
  99. #include "cursors/perspective_small_mask.xbm"
  100. #include "cursors/flip_horizontal_small.xbm"
  101. #include "cursors/flip_horizontal_small_mask.xbm"
  102. #include "cursors/flip_vertical_small.xbm"
  103. #include "cursors/flip_vertical_small_mask.xbm"
  104. #include "cursors/text_small.xbm"
  105. #include "cursors/text_small_mask.xbm"
  106. #include "cursors/dropper_small.xbm"
  107. #include "cursors/dropper_small_mask.xbm"
  108. #include "cursors/bucket_fill_small.xbm"
  109. #include "cursors/bucket_fill_small_mask.xbm"
  110. #include "cursors/blend_small.xbm"
  111. #include "cursors/blend_small_mask.xbm"
  112. #include "cursors/pencil_small.xbm"
  113. #include "cursors/pencil_small_mask.xbm"
  114. #include "cursors/paintbrush_small.xbm"
  115. #include "cursors/paintbrush_small_mask.xbm"
  116. #include "cursors/eraser_small.xbm"
  117. #include "cursors/eraser_small_mask.xbm"
  118. #include "cursors/airbrush_small.xbm"
  119. #include "cursors/airbrush_small_mask.xbm"
  120. #include "cursors/clone_small.xbm"
  121. #include "cursors/clone_small_mask.xbm"
  122. #include "cursors/blur_small.xbm"
  123. #include "cursors/blur_small_mask.xbm"
  124. #include "cursors/ink_small.xbm"
  125. #include "cursors/ink_small_mask.xbm"
  126. #include "cursors/dodge_small.xbm"
  127. #include "cursors/dodge_small_mask.xbm"
  128. #include "cursors/burn_small.xbm"
  129. #include "cursors/burn_small_mask.xbm"
  130. #include "cursors/smudge_small.xbm"
  131. #include "cursors/smudge_small_mask.xbm"
  132. #include "cursors/measure_small.xbm"
  133. #include "cursors/measure_small_mask.xbm"
  134.  
  135.  
  136. /*  Global Data  */
  137. Tool * active_tool = NULL;
  138.  
  139. /*  Local  Data  */
  140. static GtkWidget * options_shell        = NULL;
  141. static GtkWidget * options_vbox         = NULL;
  142. static GtkWidget * options_label        = NULL;
  143. static GtkWidget * options_pixmap       = NULL;
  144. static GtkWidget * options_eventbox     = NULL;
  145. static GtkWidget * options_reset_button = NULL;
  146.  
  147. static gint global_tool_ID = 0;
  148.  
  149. ToolInfo tool_info[] =
  150. {
  151.   {
  152.     NULL,
  153.     N_("Rect Select"),
  154.     N_("/Tools/Select Tools/Rect Select"),
  155.     "R",
  156.     (char **) rect_bits,
  157.     NULL,
  158.     NULL,
  159.     N_("Select rectangular regions"),
  160.     "tools/rect_select.html",
  161.     RECT_SELECT,
  162.     tools_new_rect_select,
  163.     tools_free_rect_select, 
  164.     NULL,
  165.     NULL,
  166.     NULL,
  167.     {
  168.       rect_select_small_bits, rect_select_small_mask_bits,
  169.       rect_select_small_width, rect_select_small_height,
  170.       0, 0, NULL, NULL, NULL
  171.     },
  172.     {
  173.       NULL, NULL,
  174.       0, 0,
  175.       0, 0, NULL, NULL, NULL
  176.     }
  177.   },
  178.  
  179.   {
  180.     NULL,
  181.     N_("Ellipse Select"),
  182.     N_("/Tools/Select Tools/Ellipse Select"),
  183.     "E",
  184.     (char **) circ_bits,
  185.     NULL,
  186.     NULL,
  187.     N_("Select elliptical regions"),
  188.     "tools/ellipse_select.html",
  189.     ELLIPSE_SELECT,
  190.     tools_new_ellipse_select,
  191.     tools_free_ellipse_select,
  192.     NULL,
  193.     NULL,
  194.     NULL,
  195.     {
  196.       ellipse_select_small_bits, ellipse_select_small_mask_bits,
  197.       ellipse_select_small_width, ellipse_select_small_height,
  198.       0, 0, NULL, NULL, NULL
  199.     },
  200.     {
  201.       NULL, NULL,
  202.       0, 0,
  203.       0, 0, NULL, NULL, NULL
  204.     }
  205.   },
  206.  
  207.   {
  208.     NULL, 
  209.     N_("Free Select"), 
  210.     N_("/Tools/Select Tools/Free Select"),
  211.     "F",
  212.     (char **) free_bits,
  213.     NULL,
  214.     NULL,
  215.     N_("Select hand-drawn regions"),
  216.     "tools/free_select.html",
  217.     FREE_SELECT,
  218.     tools_new_free_select,
  219.     tools_free_free_select, 
  220.     NULL,
  221.     NULL,
  222.     NULL,
  223.     {
  224.       free_select_small_bits, free_select_small_mask_bits,
  225.       free_select_small_width, free_select_small_height,
  226.       0, 0, NULL, NULL, NULL
  227.     },
  228.     {
  229.       NULL, NULL,
  230.       0, 0,
  231.       0, 0, NULL, NULL, NULL
  232.     }
  233.   },
  234.   
  235.   {
  236.     NULL,
  237.     N_("Fuzzy Select"),
  238.     N_("/Tools/Select Tools/Fuzzy Select"),
  239.     "Z",
  240.     (char **) fuzzy_bits,
  241.     NULL,
  242.     NULL,
  243.     N_("Select contiguous regions"),
  244.     "tools/fuzzy_select.html",
  245.     FUZZY_SELECT,
  246.     tools_new_fuzzy_select,
  247.     tools_free_fuzzy_select, 
  248.     NULL,
  249.     NULL,
  250.     NULL,
  251.     {
  252.       fuzzy_select_small_bits, fuzzy_select_small_mask_bits,
  253.       fuzzy_select_small_width, fuzzy_select_small_height,
  254.       0, 0, NULL, NULL, NULL
  255.     },
  256.     {
  257.       NULL, NULL,
  258.       0, 0,
  259.       0, 0, NULL, NULL, NULL
  260.     }
  261.   },
  262.   
  263.   {
  264.     NULL,
  265.     N_("Bezier Select"),
  266.     N_("/Tools/Select Tools/Bezier Select"),
  267.     "B",
  268.     (char **) bezier_bits,
  269.     NULL,
  270.     NULL,
  271.     N_("Select regions using Bezier curves"),
  272.     "tools/bezier_select.html",
  273.     BEZIER_SELECT,
  274.     tools_new_bezier_select,
  275.     tools_free_bezier_select,
  276.     NULL,
  277.     NULL,
  278.     NULL,
  279.     {
  280.       bezier_select_small_bits, bezier_select_small_mask_bits,
  281.       bezier_select_small_width, bezier_select_small_height,
  282.       0, 0, NULL, NULL, NULL
  283.     },
  284.     {
  285.       NULL, NULL,
  286.       0, 0,
  287.       0, 0, NULL, NULL, NULL
  288.     }
  289.   },
  290.   
  291.   {
  292.     NULL,
  293.     N_("Intelligent Scissors"),
  294.     N_("/Tools/Select Tools/Intelligent Scissors"),
  295.     "I",
  296.     (char **) iscissors_bits,
  297.     NULL,
  298.     NULL,
  299.     N_("Select shapes from image"),
  300.     "tools/intelligent_scissors.html",
  301.     ISCISSORS,
  302.     tools_new_iscissors,
  303.     tools_free_iscissors, 
  304.     NULL,
  305.     NULL,
  306.     NULL,
  307.     {
  308.       scissors_small_bits, scissors_small_mask_bits,
  309.       scissors_small_width, scissors_small_height,
  310.       0, 0, NULL, NULL, NULL
  311.     },
  312.     {
  313.       NULL, NULL,
  314.       0, 0,
  315.       0, 0, NULL, NULL, NULL
  316.     }
  317.   },
  318.   
  319.   {
  320.     NULL,
  321.     N_("Move"),
  322.     N_("/Tools/Transform Tools/Move"),
  323.     "M",
  324.     (char **) move_bits,
  325.     NULL,
  326.     NULL,
  327.     N_("Move layers & selections"),
  328.     "tools/move.html",
  329.     MOVE,
  330.     tools_new_move_tool,
  331.     tools_free_move_tool, 
  332.     NULL,
  333.     NULL,
  334.     NULL,
  335.     {
  336.       move_small_bits, move_small_mask_bits,
  337.       move_small_width, move_small_height,
  338.       0, 0, NULL, NULL, NULL
  339.     },
  340.     {
  341.       NULL, NULL,
  342.       0, 0,
  343.       0, 0, NULL, NULL, NULL
  344.     }
  345.   },
  346.  
  347.   {
  348.     NULL,
  349.     N_("Magnify"),
  350.     N_("/Tools/Transform Tools/Magnify"),
  351.     "<shift>M",
  352.     (char **) magnify_bits,
  353.     NULL,
  354.     NULL,
  355.     N_("Zoom in & out"),
  356.     "tools/magnify.html",
  357.     MAGNIFY,
  358.     tools_new_magnify,
  359.     tools_free_magnify, 
  360.     NULL,
  361.     NULL,
  362.     NULL,
  363.     {
  364.       zoom_small_bits, zoom_small_mask_bits,
  365.       zoom_small_width, zoom_small_height,
  366.       0, 0, NULL, NULL, NULL
  367.     },
  368.     {
  369.       NULL, NULL,
  370.       0, 0,
  371.       0, 0, NULL, NULL, NULL
  372.     }
  373.   },
  374.  
  375.   {
  376.     NULL,
  377.     N_("Crop & Resize"),
  378.     N_("/Tools/Transform Tools/Crop & Resize"),
  379.     "<shift>C",
  380.     (char **) crop_bits,
  381.     NULL,
  382.     NULL,
  383.     N_("Crop or resize the image"),
  384.     "tools/crop.html",
  385.     CROP,
  386.     tools_new_crop,
  387.     tools_free_crop,
  388.     NULL,
  389.     NULL,
  390.     NULL,
  391.     {
  392.       crop_small_bits, crop_small_mask_bits,
  393.       crop_small_width, crop_small_height,
  394.       0, 0, NULL, NULL, NULL
  395.     },
  396.     {
  397.       resize_small_bits, resize_small_mask_bits,
  398.       resize_small_width, resize_small_height,
  399.       0, 0, NULL, NULL, NULL
  400.     }
  401.   },
  402.   
  403.   {
  404.     NULL,
  405.     N_("Transform"),
  406.     N_("/Tools/Transform Tools/Transform"),
  407.     "<shift>T",
  408.     (char **) scale_bits,
  409.     NULL,
  410.     NULL,
  411.     N_("Rotation, scaling, shearing, perspective."),
  412.     "tools/transform.html",
  413.     ROTATE,
  414.     tools_new_transform_tool,
  415.     tools_free_transform_tool,
  416.     NULL,
  417.     NULL,
  418.     NULL,
  419.     {
  420.       rotate_small_bits, rotate_small_mask_bits,
  421.       rotate_small_width, rotate_small_height,
  422.       0, 0, NULL, NULL, NULL
  423.     },
  424.     {
  425.       NULL, NULL,
  426.       0, 0,
  427.       0, 0, NULL, NULL, NULL
  428.     }
  429.   }, /* rotate */
  430.   
  431.   {
  432.     NULL,
  433.     N_("Transform"),
  434.     NULL,
  435.     NULL,
  436.     (char **) scale_bits,
  437.     NULL,
  438.     NULL,
  439.     N_("Rotation, scaling, shearing, perspective."),
  440.     "tools/transform.html",
  441.     SCALE,
  442.     tools_new_transform_tool,
  443.     tools_free_transform_tool, 
  444.     NULL,
  445.     NULL,
  446.     NULL,
  447.     {
  448.       resize_small_bits, resize_small_mask_bits,
  449.       resize_small_width, resize_small_height,
  450.       0, 0, NULL, NULL, NULL
  451.     },
  452.     {
  453.       NULL, NULL,
  454.       0, 0,
  455.       0, 0, NULL, NULL, NULL
  456.     }
  457.   }, /* scale */
  458.   
  459.   {
  460.     NULL,
  461.     N_("Transform"),
  462.     NULL,
  463.     NULL,
  464.     (char **) scale_bits,
  465.     NULL,
  466.     NULL,
  467.     N_("Rotation, scaling, shearing, perspective."),
  468.     "tools/transform.html",
  469.     SHEAR,
  470.     tools_new_transform_tool,
  471.     tools_free_transform_tool,
  472.     NULL,
  473.     NULL,
  474.     NULL,
  475.     {
  476.       shear_small_bits, shear_small_mask_bits,
  477.       shear_small_width, shear_small_height,
  478.       0, 0, NULL, NULL, NULL
  479.     },
  480.     {
  481.       NULL, NULL,
  482.       0, 0,
  483.       0, 0, NULL, NULL, NULL
  484.     }
  485.   }, /* shear */
  486.   
  487.   {
  488.     NULL,
  489.     N_("Transform"),
  490.     NULL,
  491.     NULL,
  492.     (char **) scale_bits,
  493.     NULL,
  494.     NULL,
  495.     N_("Rotation, scaling, shearing, perspective."),
  496.     "tools/transform.html",
  497.     PERSPECTIVE,
  498.     tools_new_transform_tool,
  499.     tools_free_transform_tool,
  500.     NULL,
  501.     NULL,
  502.     NULL,
  503.     {
  504.       perspective_small_bits, perspective_small_mask_bits,
  505.       perspective_small_width, perspective_small_height,
  506.       0, 0, NULL, NULL, NULL
  507.     },
  508.     {
  509.       NULL, NULL,
  510.       0, 0,
  511.       0, 0, NULL, NULL, NULL
  512.     }
  513.   }, /* perspective */
  514.   
  515.   {
  516.     NULL,
  517.     N_("Flip"),
  518.     N_("/Tools/Transform Tools/Flip"),
  519.     "<shift>F",
  520.     (char **) flip_bits,
  521.     NULL,
  522.     NULL,
  523.     N_("Flip the layer or selection"),
  524.     "tools/flip.html",
  525.     FLIP,
  526.     tools_new_flip,
  527.     tools_free_flip_tool,
  528.     NULL,
  529.     NULL,
  530.     NULL,
  531.     {
  532.       flip_horizontal_small_bits, flip_horizontal_small_mask_bits,
  533.       flip_horizontal_small_width, flip_horizontal_small_height,
  534.       0, 0, NULL, NULL, NULL
  535.     },
  536.     {
  537.       flip_vertical_small_bits, flip_vertical_small_mask_bits,
  538.       flip_vertical_small_width, flip_vertical_small_height,
  539.       0, 0, NULL, NULL, NULL
  540.     }
  541.   },
  542.     
  543.   {
  544.     NULL,
  545.     N_("Text"),
  546.     N_("/Tools/Text"),
  547.     "T",
  548.     (char **) text_bits,
  549.     NULL,
  550.     NULL,
  551.     N_("Add text to the image"),
  552.     "tools/text.html",
  553.     TEXT,
  554.     tools_new_text,
  555.     tools_free_text,
  556.     NULL,
  557.     NULL,
  558.     NULL,
  559.     {
  560.       text_small_bits, text_small_mask_bits,
  561.       text_small_width, text_small_height,
  562.       0, 0, NULL, NULL, NULL
  563.     },
  564.     {
  565.       NULL, NULL,
  566.       0, 0,
  567.       0, 0, NULL, NULL, NULL
  568.     }
  569.   },
  570.   
  571.   {
  572.     NULL,
  573.     N_("Color Picker"),
  574.     N_("/Tools/Color Picker"),
  575.     "O",
  576.     (char **) colorpicker_bits,
  577.     NULL,
  578.     NULL,
  579.     N_("Pick colors from the image"),
  580.     "tools/color_picker.html",
  581.     COLOR_PICKER,
  582.     tools_new_color_picker,
  583.     tools_free_color_picker,
  584.     NULL,
  585.     NULL,
  586.     NULL,
  587.     {
  588.       dropper_small_bits, dropper_small_mask_bits,
  589.       dropper_small_width, dropper_small_height,
  590.       0, 0, NULL, NULL, NULL
  591.     },
  592.     {
  593.       NULL, NULL,
  594.       0, 0,
  595.       0, 0, NULL, NULL, NULL
  596.     }
  597.   },
  598.   
  599.   { 
  600.     NULL,
  601.     N_("Bucket Fill"),
  602.     N_("/Tools/Paint Tools/Bucket Fill"),
  603.     "<shift>B",
  604.     (char **) fill_bits,
  605.     NULL,
  606.     NULL,
  607.     N_("Fill with a color or pattern"),
  608.     "tools/bucket_fill.html",
  609.     BUCKET_FILL,
  610.     tools_new_bucket_fill,
  611.     tools_free_bucket_fill,
  612.     NULL,
  613.     NULL,
  614.     NULL,
  615.     {
  616.       bucket_fill_small_bits, bucket_fill_small_mask_bits,
  617.       bucket_fill_small_width, bucket_fill_small_height,
  618.       0, 0, NULL, NULL, NULL
  619.     },
  620.     {
  621.       NULL, NULL,
  622.       0, 0,
  623.       0, 0, NULL, NULL, NULL
  624.     }
  625.   },
  626.  
  627.   { 
  628.     NULL,
  629.     N_("Blend"),
  630.     N_("/Tools/Paint Tools/Blend"),
  631.     "L",
  632.     (char **) gradient_bits,
  633.     NULL,
  634.     NULL,
  635.     N_("Fill with a color gradient"),
  636.     "tools/blend.html",
  637.     BLEND,
  638.     tools_new_blend,
  639.     tools_free_blend,
  640.     NULL,
  641.     NULL,
  642.     NULL,
  643.     {
  644.       blend_small_bits, blend_small_mask_bits,
  645.       blend_small_width, blend_small_height,
  646.       0, 0, NULL, NULL, NULL
  647.     },
  648.     {
  649.       NULL, NULL,
  650.       0, 0,
  651.       0, 0, NULL, NULL, NULL
  652.     }
  653.   },
  654.   
  655.   {
  656.     NULL,
  657.     N_("Pencil"),
  658.     N_("/Tools/Paint Tools/Pencil"),
  659.     "<shift>P",
  660.     (char **) pencil_bits,
  661.     NULL,
  662.     NULL,
  663.     N_("Draw sharp pencil strokes"),
  664.     "tools/pencil.html",
  665.     PENCIL,
  666.     tools_new_pencil,
  667.     tools_free_pencil,
  668.     NULL,
  669.     NULL,
  670.     NULL,
  671.     {
  672.       pencil_small_bits, pencil_small_mask_bits,
  673.       pencil_small_width, pencil_small_height,
  674.       0, 0, NULL, NULL, NULL
  675.     },
  676.     {
  677.       NULL, NULL,
  678.       0, 0,
  679.       0, 0, NULL, NULL, NULL
  680.     }
  681.   },
  682.   
  683.   {
  684.     NULL,
  685.     N_("Paintbrush"),
  686.     N_("/Tools/Paint Tools/Paintbrush"),
  687.     "P",
  688.     (char **) paint_bits,
  689.     NULL,
  690.     NULL,
  691.     N_("Paint fuzzy brush strokes"),
  692.     "tools/paintbrush.html",
  693.     PAINTBRUSH,
  694.     tools_new_paintbrush,
  695.     tools_free_paintbrush, 
  696.     NULL,
  697.     NULL,
  698.     NULL,
  699.     {
  700.       paintbrush_small_bits, paintbrush_small_mask_bits,
  701.       paintbrush_small_width, paintbrush_small_height,
  702.       0, 0, NULL, NULL, NULL
  703.     },
  704.     {
  705.       NULL, NULL,
  706.       0, 0,
  707.       0, 0, NULL, NULL, NULL
  708.     }
  709.   },
  710.   
  711.   { 
  712.     NULL,
  713.     N_("Eraser"),
  714.     N_("/Tools/Paint Tools/Eraser"),
  715.     "<shift>E",
  716.     (char **) erase_bits,
  717.     NULL,
  718.     NULL,
  719.     N_("Erase to background or transparency"),
  720.     "tools/eraser.html",
  721.     ERASER,
  722.     tools_new_eraser,
  723.     tools_free_eraser,
  724.     NULL,
  725.     NULL,
  726.     NULL,
  727.     {
  728.       eraser_small_bits, eraser_small_mask_bits,
  729.       eraser_small_width, eraser_small_height,
  730.       0, 0, NULL, NULL, NULL
  731.     },
  732.     {
  733.       NULL, NULL,
  734.       0, 0,
  735.       0, 0, NULL, NULL, NULL
  736.     }
  737.   },
  738.   
  739.   { 
  740.     NULL,
  741.     N_("Airbrush"),
  742.     N_("/Tools/Paint Tools/Airbrush"),
  743.     "A",
  744.     (char **) airbrush_bits,
  745.     NULL,
  746.     NULL,
  747.     N_("Airbrush with variable pressure"),
  748.     "tools/airbrush.html",
  749.     AIRBRUSH,
  750.     tools_new_airbrush,
  751.     tools_free_airbrush,
  752.     NULL,
  753.     NULL,
  754.     NULL,
  755.     {
  756.       airbrush_small_bits, airbrush_small_mask_bits,
  757.       airbrush_small_width, airbrush_small_height,
  758.       0, 0, NULL, NULL, NULL
  759.     },
  760.     {
  761.       NULL, NULL,
  762.       0, 0,
  763.       0, 0, NULL, NULL, NULL
  764.     }
  765.   },
  766.   
  767.   { 
  768.     NULL,
  769.     N_("Clone"),
  770.     N_("/Tools/Paint Tools/Clone"),
  771.     "C",
  772.     (char **) clone_bits,
  773.     NULL,
  774.     NULL,
  775.     N_("Paint using patterns or image regions"),
  776.     "tools/clone.html",
  777.     CLONE,
  778.     tools_new_clone,
  779.     tools_free_clone,
  780.     NULL,
  781.     NULL,
  782.     NULL,
  783.     {
  784.       clone_small_bits, clone_small_mask_bits,
  785.       clone_small_width, clone_small_height,
  786.       0, 0, NULL, NULL, NULL
  787.     },
  788.     {
  789.       NULL, NULL,
  790.       0, 0,
  791.       0, 0, NULL, NULL, NULL
  792.     }
  793.   },
  794.   
  795.   { 
  796.     NULL,
  797.     N_("Convolve"),
  798.     N_("/Tools/Paint Tools/Convolve"),
  799.     "V",
  800.     (char **) blur_bits,
  801.     NULL,
  802.     NULL,
  803.     N_("Blur or sharpen"),
  804.     "tools/convolve.html",
  805.     CONVOLVE,
  806.     tools_new_convolve,
  807.     tools_free_convolve,
  808.     NULL,
  809.     NULL,
  810.     NULL,
  811.     {
  812.       blur_small_bits, blur_small_mask_bits,
  813.       blur_small_width, blur_small_height,
  814.       0, 0, NULL, NULL, NULL
  815.     },
  816.     {
  817.       NULL, NULL,
  818.       0, 0,
  819.       0, 0, NULL, NULL, NULL
  820.     }
  821.   },
  822.  
  823.   {
  824.     NULL,
  825.     N_("Ink"),
  826.     N_("/Tools/Paint Tools/Ink"),
  827.     "K",
  828.     (char **) ink_bits,
  829.     NULL,
  830.     NULL,
  831.     N_("Draw in ink"),
  832.     "tools/ink.html",
  833.     INK,
  834.     tools_new_ink,
  835.     tools_free_ink,
  836.     NULL,
  837.     NULL,
  838.     NULL,
  839.     {
  840.       ink_small_bits, ink_small_mask_bits,
  841.       ink_small_width, ink_small_height,
  842.       0, 0, NULL, NULL, NULL
  843.     },
  844.     {
  845.       NULL, NULL,
  846.       0, 0,
  847.       0, 0, NULL, NULL, NULL
  848.     }
  849.   },
  850.  
  851.   {
  852.     NULL,
  853.     N_("Dodge or Burn"),
  854.     N_("/Tools/Paint Tools/DodgeBurn"),
  855.     "<shift>D",
  856.     (char **) dodge_bits,
  857.     NULL,
  858.     NULL,
  859.     N_("Dodge or Burn"),
  860.     "tools/dodgeburn.html",
  861.     DODGEBURN,
  862.     tools_new_dodgeburn,
  863.     tools_free_dodgeburn,
  864.     NULL,
  865.     NULL,
  866.     NULL,
  867.     {
  868.       dodge_small_bits, dodge_small_mask_bits,
  869.       dodge_small_width, dodge_small_height,
  870.       0, 0, NULL, NULL, NULL
  871.     },
  872.     {
  873.       burn_small_bits, burn_small_mask_bits,
  874.       burn_small_width, burn_small_height,
  875.       0, 0, NULL, NULL, NULL
  876.     }
  877.   },
  878.  
  879.   {
  880.     NULL,
  881.     N_("Smudge"),
  882.     N_("/Tools/Paint Tools/Smudge"),
  883.     "<shift>S",
  884.     (char **) smudge_bits,
  885.     NULL,
  886.     NULL,
  887.     N_("Smudge"),
  888.     "tools/smudge.html",
  889.     SMUDGE,
  890.     tools_new_smudge,
  891.     tools_free_smudge,
  892.     NULL,
  893.     NULL,
  894.     NULL,
  895.     {
  896.       smudge_small_bits, smudge_small_mask_bits,
  897.       smudge_small_width, smudge_small_height,
  898.       0, 0, NULL, NULL, NULL
  899.     },
  900.     {
  901.       NULL, NULL,
  902.       0, 0,
  903.       0, 0, NULL, NULL, NULL
  904.     }
  905.   },
  906.  
  907. /*
  908.   {
  909.     NULL,
  910.     N_("Xinput Airbrush"),
  911.     N_("/Tools/Paint Tools/XinputAirbrush"),
  912.     "<shift>A",
  913.     (char **) xinput_airbrush_bits,
  914.     NULL,
  915.     NULL,
  916.     N_("Natural Airbrush"),
  917.     "tools/xinput_airbrush.html",
  918.     XINPUT_AIRBRUSH,
  919.     tools_new_xinput_airbrush,
  920.     tools_free_xinput_airbrush,
  921.     NULL,
  922.     NULL,
  923.     NULL,
  924.     {
  925.       NULL, NULL,
  926.       0, 0,
  927.       0, 0, NULL, NULL, NULL
  928.     },
  929.     {
  930.       NULL, NULL,
  931.       0, 0,
  932.       0, 0, NULL, NULL, NULL
  933.     }
  934.   },          
  935. */
  936.  
  937.   {
  938.     NULL,
  939.     N_("Measure"),
  940.     N_("/Tools/Measure"),
  941.     "",
  942.      (char **) measure_bits,
  943.     NULL,
  944.     NULL,
  945.     N_("Measure distances and angles"),
  946.     "tools/measure.html",
  947.     MEASURE,
  948.     tools_new_measure_tool,
  949.     tools_free_measure_tool, 
  950.     NULL,
  951.     NULL,
  952.     NULL,
  953.     {
  954.       measure_small_bits, measure_small_mask_bits,
  955.       measure_small_width, measure_small_height,
  956.       0, 0, NULL, NULL, NULL
  957.     },
  958.     {
  959.       NULL, NULL,
  960.       0, 0,
  961.       0, 0, NULL, NULL, NULL
  962.     }
  963.   },
  964.  
  965. /*
  966.   {
  967.     NULL,
  968.     N_("Path"),
  969.     N_("/Tools/Path"),
  970.     "",
  971.     (char **) path_tool_bits,
  972.     NULL,
  973.     NULL,
  974.     N_("Manipulate paths"),
  975.     "tools/path.html",
  976.     PATH_TOOL,
  977.     tools_new_path_tool,
  978.     tools_free_path_tool, 
  979.     NULL,
  980.     NULL,
  981.     NULL,
  982.     {
  983.       NULL, NULL,
  984.       0, 0,
  985.       0, 0, NULL, NULL, NULL
  986.     },
  987.     {
  988.       NULL, NULL,
  989.       0, 0,
  990.       0, 0, NULL, NULL, NULL
  991.     }
  992.   },
  993. */
  994.  
  995.   /*  Non-toolbox tools  */
  996.   { 
  997.     NULL,
  998.     N_("By Color Select"),
  999.     N_("/Select/By Color..."),
  1000.     NULL,
  1001.     (char **) by_color_select_bits,
  1002.     NULL,
  1003.     NULL,
  1004.     N_("Select regions by color"),
  1005.     "tools/by_color_select.html",
  1006.     BY_COLOR_SELECT,
  1007.     tools_new_by_color_select,
  1008.     tools_free_by_color_select,
  1009.     by_color_select_initialize,
  1010.     NULL,
  1011.     NULL,
  1012.     {
  1013.       NULL, NULL,
  1014.       0, 0,
  1015.       0, 0, NULL, NULL, NULL
  1016.     },
  1017.     {
  1018.       NULL, NULL,
  1019.       0, 0,
  1020.       0, 0, NULL, NULL, NULL
  1021.     }
  1022.   },
  1023.   
  1024.   { 
  1025.     NULL,
  1026.     N_("Color Balance"),
  1027.     N_("/Image/Colors/Color Balance..."),
  1028.     NULL,
  1029.     (char **) adjustment_bits,
  1030.     NULL,
  1031.     NULL,
  1032.     N_("Adjust color balance"),
  1033.     "tools/color_balance.html",
  1034.     COLOR_BALANCE,
  1035.     tools_new_color_balance,
  1036.     tools_free_color_balance,
  1037.     color_balance_initialize,
  1038.     NULL,
  1039.     NULL,
  1040.     {
  1041.       NULL, NULL,
  1042.       0, 0,
  1043.       0, 0, NULL, NULL, NULL
  1044.     },
  1045.     {
  1046.       NULL, NULL,
  1047.       0, 0,
  1048.       0, 0, NULL, NULL, NULL
  1049.     }
  1050.   },
  1051.   
  1052.   { 
  1053.     NULL,
  1054.     N_("Brightness-Contrast"),
  1055.     N_("/Image/Colors/Brightness-Contrast..."),
  1056.     NULL,
  1057.     (char **) adjustment_bits,
  1058.     NULL,
  1059.     NULL,
  1060.     N_("Adjust brightness and contrast"),
  1061.     "tools/brightness_contrast.html",
  1062.     BRIGHTNESS_CONTRAST,
  1063.     tools_new_brightness_contrast,
  1064.     tools_free_brightness_contrast,
  1065.     brightness_contrast_initialize,
  1066.     NULL,
  1067.     NULL,
  1068.     {
  1069.       NULL, NULL,
  1070.       0, 0,
  1071.       0, 0, NULL, NULL, NULL
  1072.     },
  1073.     {
  1074.       NULL, NULL,
  1075.       0, 0,
  1076.       0, 0, NULL, NULL, NULL
  1077.     }
  1078.   },
  1079.   
  1080.   { 
  1081.     NULL,
  1082.     N_("Hue-Saturation"),
  1083.     N_("/Image/Colors/Hue-Saturation..."),
  1084.     NULL,
  1085.     (char **) adjustment_bits,
  1086.     NULL,
  1087.     NULL,
  1088.     N_("Adjust hue and saturation"),
  1089.     "tools/hue_saturation.html",
  1090.     HUE_SATURATION,
  1091.     tools_new_hue_saturation,
  1092.     tools_free_hue_saturation, 
  1093.     hue_saturation_initialize,
  1094.     NULL,
  1095.     NULL,
  1096.     {
  1097.       NULL, NULL,
  1098.       0, 0,
  1099.       0, 0, NULL, NULL, NULL
  1100.     },
  1101.     {
  1102.       NULL, NULL,
  1103.       0, 0,
  1104.       0, 0, NULL, NULL, NULL
  1105.     }
  1106.   },
  1107.  
  1108.   { 
  1109.     NULL,
  1110.     N_("Posterize"),
  1111.     N_("/Image/Colors/Posterize..."),
  1112.     NULL,
  1113.     (char **) adjustment_bits,
  1114.     NULL,
  1115.     NULL,
  1116.     N_("Reduce image to a fixed numer of colors"),
  1117.     "tools/posterize.html",
  1118.     POSTERIZE,
  1119.     tools_new_posterize,
  1120.     tools_free_posterize,
  1121.     posterize_initialize,
  1122.     NULL,
  1123.     NULL,
  1124.     {
  1125.       NULL, NULL,
  1126.       0, 0,
  1127.       0, 0, NULL, NULL, NULL
  1128.     },
  1129.     {
  1130.       NULL, NULL,
  1131.       0, 0,
  1132.       0, 0, NULL, NULL, NULL
  1133.     }
  1134.   },
  1135.   
  1136.   { 
  1137.     NULL,
  1138.     N_("Threshold"), 
  1139.     N_("/Image/Colors/Threshold..."),
  1140.     NULL,
  1141.     (char **) levels_bits,
  1142.     NULL,
  1143.     NULL,
  1144.     N_("Reduce image to two colors using a threshold"),
  1145.     "tools/threshold.html",
  1146.     THRESHOLD,
  1147.     tools_new_threshold,
  1148.     tools_free_threshold,
  1149.     threshold_initialize,
  1150.     NULL,
  1151.     NULL,
  1152.     {
  1153.       NULL, NULL,
  1154.       0, 0,
  1155.       0, 0, NULL, NULL, NULL
  1156.     },
  1157.     {
  1158.       NULL, NULL,
  1159.       0, 0,
  1160.       0, 0, NULL, NULL, NULL
  1161.     }
  1162.   },
  1163.   
  1164.   { 
  1165.     NULL,
  1166.     N_("Curves"),
  1167.     N_("/Image/Colors/Curves..."),
  1168.     NULL,
  1169.     (char **) curves_bits,
  1170.     NULL,
  1171.     NULL,
  1172.     N_("Adjust color curves"),
  1173.     "tools/curves.html",
  1174.     CURVES,
  1175.     tools_new_curves, 
  1176.     tools_free_curves,
  1177.     curves_initialize,
  1178.     NULL,
  1179.     NULL,
  1180.     {
  1181.       NULL, NULL,
  1182.       0, 0,
  1183.       0, 0, NULL, NULL, NULL
  1184.     },
  1185.     {
  1186.       NULL, NULL,
  1187.       0, 0,
  1188.       0, 0, NULL, NULL, NULL
  1189.     }
  1190.   },
  1191.   
  1192.   { 
  1193.     NULL,
  1194.     N_("Levels"),
  1195.     N_("/Image/Colors/Levels..."),
  1196.     NULL,
  1197.     (char **) levels_bits,
  1198.     NULL,
  1199.     NULL,
  1200.     N_("Adjust color levels"),
  1201.     "tools/levels.html",
  1202.     LEVELS,
  1203.     tools_new_levels, 
  1204.     tools_free_levels,
  1205.     levels_initialize,
  1206.     NULL,
  1207.     NULL,
  1208.     {
  1209.       NULL, NULL,
  1210.       0, 0,
  1211.       0, 0, NULL, NULL, NULL
  1212.     },
  1213.     {
  1214.       NULL, NULL,
  1215.       0, 0,
  1216.       0, 0, NULL, NULL, NULL
  1217.     }
  1218.   },
  1219.   
  1220.   { 
  1221.     NULL,
  1222.     N_("Histogram"),
  1223.     N_("/Image/Histogram..."),
  1224.     NULL,
  1225.     (char **) histogram_bits,
  1226.     NULL,
  1227.     NULL,
  1228.     N_("View image histogram"),
  1229.     "tools/histogram.html",
  1230.     HISTOGRAM,
  1231.     tools_new_histogram_tool,
  1232.     tools_free_histogram_tool,
  1233.     histogram_tool_initialize ,
  1234.     NULL,
  1235.     NULL,
  1236.     {
  1237.       NULL, NULL,
  1238.       0, 0,
  1239.       0, 0, NULL, NULL, NULL
  1240.     },
  1241.     {
  1242.       NULL, NULL,
  1243.       0, 0,
  1244.       0, 0, NULL, NULL, NULL
  1245.     }
  1246.   }
  1247. };
  1248.  
  1249. gint num_tools = sizeof (tool_info) / sizeof (tool_info[0]);
  1250.  
  1251. /*  dnd stuff  */
  1252. static GtkTargetEntry tool_target_table[] =
  1253. {
  1254.   GIMP_TARGET_TOOL
  1255. };
  1256. static guint n_tool_targets = (sizeof (tool_target_table) /
  1257.                                sizeof (tool_target_table[0]));
  1258.  
  1259.  
  1260. /*  Local function declarations  */
  1261. static void      tool_options_show           (ToolType);
  1262. static void      tool_options_hide           (ToolType);
  1263. static ToolType  tool_options_drag_tool      (GtkWidget *, gpointer);
  1264. static void      tool_options_drop_tool      (GtkWidget *, ToolType, gpointer);
  1265. static void      tool_options_reset_callback (GtkWidget *, gpointer);
  1266. static void      tool_options_close_callback (GtkWidget *, gpointer);
  1267.  
  1268.  
  1269. /*  Function definitions  */
  1270.  
  1271. static void
  1272. active_tool_free (void)
  1273. {
  1274.   if (!active_tool)
  1275.     return;
  1276.  
  1277.   tool_options_hide (active_tool->type);
  1278.  
  1279.   (* tool_info[(gint) active_tool->type].free_func) (active_tool);
  1280.  
  1281.   g_free (active_tool);
  1282.   active_tool = NULL;
  1283. }
  1284.  
  1285. void
  1286. tools_select (ToolType tool_type)
  1287. {
  1288.   if (active_tool)
  1289.     active_tool_free ();
  1290.  
  1291.   active_tool = (* tool_info[(gint) tool_type].new_func) ();
  1292.  
  1293.   tool_options_show (active_tool->type);
  1294. }
  1295.  
  1296. void
  1297. tools_initialize (ToolType  tool_type,
  1298.           GDisplay *gdisp)
  1299. {
  1300.   /*  Tools which have an init function have dialogs and
  1301.    *  cannot be initialized without a display
  1302.    */
  1303.   if (tool_info[(gint) tool_type].init_func && !gdisp)
  1304.     tool_type = RECT_SELECT;
  1305.  
  1306.   /*  Force the emission of the "tool_changed" signal
  1307.    */
  1308.   if (active_tool->type == tool_type)
  1309.     {
  1310.       gimp_context_tool_changed (gimp_context_get_user ());
  1311.     }
  1312.   else
  1313.     {
  1314.       gimp_context_set_tool (gimp_context_get_user (), tool_type);
  1315.     }
  1316.  
  1317.   if (tool_info[(gint) tool_type].init_func)
  1318.     {
  1319.       (* tool_info[(gint) tool_type].init_func) (gdisp);
  1320.  
  1321.       active_tool->drawable = gimage_active_drawable (gdisp->gimage);
  1322.     }
  1323.  
  1324.   /*  don't set gdisp_ptr here! (see commands.c)  */
  1325. }
  1326.  
  1327.  
  1328. void
  1329. active_tool_control (ToolAction  action,
  1330.              void       *gdisp_ptr)
  1331. {
  1332.   if (active_tool)
  1333.     {
  1334.       if (active_tool->gdisp_ptr == gdisp_ptr)
  1335.     {
  1336.       switch (action)
  1337.         {
  1338.         case PAUSE :
  1339.           if (active_tool->state == ACTIVE)
  1340.         {
  1341.           if (! active_tool->paused_count)
  1342.             {
  1343.               active_tool->state = PAUSED;
  1344.               (* active_tool->control_func) (active_tool, action, gdisp_ptr);
  1345.             }
  1346.         }
  1347.           active_tool->paused_count++;
  1348.           break;
  1349.  
  1350.         case RESUME :
  1351.           active_tool->paused_count--;
  1352.           if (active_tool->state == PAUSED)
  1353.         {
  1354.           if (! active_tool->paused_count)
  1355.             {
  1356.               active_tool->state = ACTIVE;
  1357.               (* active_tool->control_func) (active_tool, action, gdisp_ptr);
  1358.             }
  1359.         }
  1360.           break;
  1361.  
  1362.         case HALT :
  1363.           active_tool->state = INACTIVE;
  1364.           (* active_tool->control_func) (active_tool, action, gdisp_ptr);
  1365.           break;
  1366.  
  1367.         case DESTROY :
  1368.               active_tool_free ();
  1369.               gtk_widget_hide (options_shell);
  1370.               break;
  1371.  
  1372.         default:
  1373.           break;
  1374.         }
  1375.     }
  1376.       else if (action == HALT)
  1377.     {
  1378.       active_tool->state = INACTIVE;
  1379.     }
  1380.     }
  1381. }
  1382.  
  1383. /*  standard member functions  */
  1384.  
  1385. static void
  1386. standard_button_press_func (Tool           *tool,
  1387.                 GdkEventButton *bevent,
  1388.                 gpointer        gdisp_ptr)
  1389. {
  1390.   GDisplay *gdisp;
  1391.  
  1392.   gdisp = gdisp_ptr;
  1393.  
  1394.   tool->gdisp_ptr = gdisp;
  1395.   tool->drawable = gimage_active_drawable (gdisp->gimage);
  1396. }
  1397.  
  1398. static void
  1399. standard_button_release_func (Tool           *tool,
  1400.                   GdkEventButton *bevent,
  1401.                   gpointer        gdisp_ptr)
  1402. {
  1403. }
  1404.  
  1405. static void
  1406. standard_motion_func (Tool           *tool,
  1407.               GdkEventMotion *mevent,
  1408.               gpointer        gdisp_ptr)
  1409. {
  1410. }
  1411.  
  1412. static void
  1413. standard_arrow_keys_func (Tool        *tool,
  1414.               GdkEventKey *kevent,
  1415.               gpointer     gdisp_ptr)
  1416. {
  1417. }
  1418.  
  1419. static void
  1420. standard_modifier_key_func (Tool        *tool,
  1421.                 GdkEventKey *kevent,
  1422.                 gpointer     gdisp_ptr)
  1423. {
  1424. }
  1425.  
  1426. static void
  1427. standard_cursor_update_func (Tool           *tool,
  1428.                  GdkEventMotion *mevent,
  1429.                  gpointer        gdisp_ptr)
  1430. {
  1431.   GDisplay *gdisp;
  1432.  
  1433.   gdisp = (GDisplay *) gdisp_ptr;
  1434.   gdisplay_install_tool_cursor (gdisp, GDK_TOP_LEFT_ARROW,
  1435.                 TOOL_TYPE_NONE,
  1436.                 CURSOR_MODIFIER_NONE,
  1437.                 FALSE);
  1438. }
  1439.  
  1440. static void
  1441. standard_operator_update_func (Tool           *tool,
  1442.                    GdkEventMotion *mevent,
  1443.                    gpointer        gdisp_ptr)
  1444. {
  1445. }
  1446.  
  1447. static void
  1448. standard_control_func (Tool       *tool,
  1449.                ToolAction  action,
  1450.                gpointer    gdisp_ptr)
  1451. {
  1452. }
  1453.  
  1454. /*  Create a default tool structure 
  1455.  *
  1456.  *  TODO: objectifying the tools will remove lots of code duplication
  1457.  */
  1458.  
  1459. Tool *
  1460. tools_new_tool (ToolType tool_type)
  1461. {
  1462.   Tool *tool;
  1463.  
  1464.   tool = g_new (Tool, 1);
  1465.  
  1466.   tool->type = tool_type;
  1467.   tool->ID   = global_tool_ID++;
  1468.  
  1469.   tool->state        = INACTIVE;
  1470.   tool->paused_count = 0;
  1471.   tool->scroll_lock  = FALSE;     /*  Allow scrolling  */
  1472.   tool->auto_snap_to = TRUE;      /*  Snap to guides   */
  1473.  
  1474.   tool->preserve  = TRUE;         /*  Preserve tool across drawable changes  */
  1475.   tool->gdisp_ptr = NULL;
  1476.   tool->drawable  = NULL;
  1477.  
  1478.   tool->toggled   = FALSE;
  1479.  
  1480.   tool->private   = NULL;
  1481.  
  1482.   tool->button_press_func   = standard_button_press_func;
  1483.   tool->button_release_func = standard_button_release_func;
  1484.   tool->motion_func         = standard_motion_func;
  1485.   tool->arrow_keys_func     = standard_arrow_keys_func;
  1486.   tool->modifier_key_func   = standard_modifier_key_func;
  1487.   tool->cursor_update_func  = standard_cursor_update_func;
  1488.   tool->oper_update_func    = standard_operator_update_func;
  1489.   tool->control_func        = standard_control_func;
  1490.  
  1491.   return tool;
  1492. }
  1493.  
  1494. void
  1495. tools_help_func (const gchar *help_data)
  1496. {
  1497.   gimp_standard_help_func (tool_info[(gint) active_tool->type].private_tip);
  1498. }
  1499.  
  1500. void
  1501. tools_register (ToolType     tool_type,
  1502.         ToolOptions *tool_options)
  1503. {
  1504.   g_return_if_fail (tool_options != NULL);
  1505.  
  1506.   tool_info [(gint) tool_type].tool_options = tool_options;
  1507.  
  1508.   /*  need to check whether the widget is visible...this can happen
  1509.    *  because some tools share options such as the transformation tools
  1510.    */
  1511.   if (! GTK_WIDGET_VISIBLE (tool_options->main_vbox))
  1512.     {
  1513.       gtk_box_pack_start (GTK_BOX (options_vbox), tool_options->main_vbox,
  1514.               TRUE, TRUE, 0);
  1515.       gtk_widget_show (tool_options->main_vbox);
  1516.     }
  1517.  
  1518.   gtk_label_set_text (GTK_LABEL (options_label), tool_options->title);
  1519.  
  1520.   gtk_pixmap_set (GTK_PIXMAP (options_pixmap),
  1521.           tool_get_pixmap (tool_type), tool_get_mask (tool_type));
  1522.  
  1523.   gtk_widget_queue_draw (options_pixmap);
  1524.  
  1525.   gimp_help_set_help_data (options_eventbox,
  1526.                gettext (tool_info[(gint) tool_type].tool_desc),
  1527.                tool_info[(gint) tool_type].private_tip);
  1528. }
  1529.  
  1530. /*  Tool options function  */
  1531.  
  1532. void
  1533. tool_options_dialog_new (void)
  1534. {
  1535.   GtkWidget *frame;
  1536.   GtkWidget *hbox;
  1537.   GtkWidget *vbox;
  1538.  
  1539.   /*  The shell and main vbox  */
  1540.   options_shell =
  1541.     gimp_dialog_new (_("Tool Options"), "tool_options",
  1542.              tools_help_func,
  1543.              "dialogs/tool_options.html",
  1544.              GTK_WIN_POS_NONE,
  1545.              FALSE, TRUE, TRUE,
  1546.  
  1547.              _("Reset"), tool_options_reset_callback,
  1548.              NULL, NULL, &options_reset_button, FALSE, FALSE,
  1549.              _("Close"), tool_options_close_callback,
  1550.              NULL, NULL, NULL, TRUE, TRUE,
  1551.  
  1552.              NULL);
  1553.  
  1554.   /*  Register dialog  */
  1555.   dialog_register (options_shell);
  1556.   session_set_window_geometry (options_shell, &tool_options_session_info,
  1557.                    FALSE );
  1558.  
  1559.   /*  The outer frame  */
  1560.   frame = gtk_frame_new (NULL);
  1561.   gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
  1562.   gtk_container_add (GTK_CONTAINER (GTK_DIALOG (options_shell)->vbox), frame);
  1563.   gtk_widget_show (frame);
  1564.  
  1565.   /*  The vbox containing the title frame and the options vbox  */
  1566.   vbox = gtk_vbox_new (FALSE, 0);
  1567.   gtk_container_add (GTK_CONTAINER (frame), vbox);
  1568.   gtk_widget_show (vbox);
  1569.  
  1570.   /*  The title frame  */
  1571.   frame = gtk_frame_new (NULL);
  1572.   gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
  1573.   gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
  1574.   gtk_widget_show (frame);
  1575.  
  1576.   options_eventbox = gtk_event_box_new ();
  1577.   gtk_container_add (GTK_CONTAINER (frame), options_eventbox);
  1578.   gtk_widget_show (options_eventbox);
  1579.  
  1580.   hbox = gtk_hbox_new (FALSE, 4);
  1581.   gtk_container_add (GTK_CONTAINER (options_eventbox), hbox);
  1582.   gtk_widget_show (hbox);
  1583.  
  1584.   options_pixmap = gtk_pixmap_new (tool_get_pixmap (RECT_SELECT), tool_get_mask (RECT_SELECT));
  1585.   gtk_box_pack_start (GTK_BOX (hbox), options_pixmap, FALSE, FALSE, 0);
  1586.   gtk_widget_show (options_pixmap);
  1587.  
  1588.   options_label = gtk_label_new ("");
  1589.   gtk_box_pack_start (GTK_BOX (hbox), options_label, FALSE, FALSE, 1);
  1590.   gtk_widget_show (options_label);
  1591.  
  1592.   options_vbox = gtk_vbox_new (FALSE, 0);
  1593.   gtk_container_set_border_width (GTK_CONTAINER (options_vbox), 2);
  1594.   gtk_box_pack_start (GTK_BOX (vbox), options_vbox, FALSE, FALSE, 0);
  1595.  
  1596.   gtk_widget_show (options_vbox);
  1597.  
  1598.   /*  hide the separator between the dialog's vbox and the action area  */
  1599.   gtk_widget_hide (GTK_WIDGET (g_list_nth_data (gtk_container_children (GTK_CONTAINER (GTK_BIN (options_shell)->child)), 1)));
  1600.  
  1601.   /*  dnd stuff  */
  1602.   gtk_drag_dest_set (options_shell,
  1603.              GTK_DEST_DEFAULT_HIGHLIGHT |
  1604.              GTK_DEST_DEFAULT_MOTION |
  1605.              GTK_DEST_DEFAULT_DROP,
  1606.              tool_target_table, n_tool_targets,
  1607.              GDK_ACTION_COPY); 
  1608.   gimp_dnd_tool_dest_set (options_shell, tool_options_drop_tool, NULL);
  1609.  
  1610.   gtk_drag_source_set (options_eventbox,
  1611.                GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
  1612.                tool_target_table, n_tool_targets,
  1613.                GDK_ACTION_COPY); 
  1614.   gimp_dnd_tool_source_set (options_eventbox, tool_options_drag_tool, NULL);
  1615. }
  1616.  
  1617. void
  1618. tool_options_dialog_free (void)
  1619. {
  1620.   session_get_window_info (options_shell, &tool_options_session_info);
  1621.   gtk_widget_destroy (options_shell);
  1622. }
  1623.  
  1624. void
  1625. tool_options_dialog_show (void)
  1626. {
  1627.   if (!GTK_WIDGET_VISIBLE (options_shell)) 
  1628.     {
  1629.       gtk_widget_show (options_shell);
  1630.     } 
  1631.   else 
  1632.     {
  1633.       gdk_window_raise (options_shell->window);
  1634.     }
  1635. }
  1636.  
  1637. static void
  1638. tool_options_show (ToolType tool_type)
  1639. {
  1640.   if (tool_info[tool_type].tool_options->main_vbox)
  1641.     gtk_widget_show (tool_info[tool_type].tool_options->main_vbox);
  1642.  
  1643.   if (tool_info[tool_type].tool_options->title)
  1644.     gtk_label_set_text (GTK_LABEL (options_label),
  1645.             tool_info[tool_type].tool_options->title);
  1646.  
  1647.   gtk_pixmap_set (GTK_PIXMAP (options_pixmap),
  1648.           tool_get_pixmap (tool_type), tool_get_mask (tool_type));
  1649.  
  1650.   gtk_widget_queue_draw (options_pixmap);
  1651.  
  1652.   gimp_help_set_help_data (options_label->parent->parent,
  1653.                gettext (tool_info[(gint) tool_type].tool_desc),
  1654.                tool_info[(gint) tool_type].private_tip);
  1655.  
  1656.   if (tool_info[tool_type].tool_options->reset_func)
  1657.     gtk_widget_set_sensitive (options_reset_button, TRUE);
  1658.   else
  1659.     gtk_widget_set_sensitive (options_reset_button, FALSE);
  1660. }
  1661.  
  1662. static void
  1663. tool_options_hide (ToolType tool_type)
  1664. {
  1665.   if (tool_info[tool_type].tool_options)
  1666.     gtk_widget_hide (tool_info[tool_type].tool_options->main_vbox);
  1667. }
  1668.  
  1669. /*  Tool options callbacks  */
  1670.  
  1671. static void
  1672. tool_options_drop_tool (GtkWidget *widget,
  1673.             ToolType   tool,
  1674.             gpointer   data)
  1675. {
  1676.   gimp_context_set_tool (gimp_context_get_user (), tool);
  1677. }
  1678.  
  1679. ToolType
  1680. tool_options_drag_tool (GtkWidget *widget,
  1681.             gpointer   data)
  1682. {
  1683.   return gimp_context_get_tool (gimp_context_get_user ());
  1684. }
  1685.  
  1686. static void
  1687. tool_options_close_callback (GtkWidget *widget,
  1688.                  gpointer   data)
  1689. {
  1690.   GtkWidget *shell;
  1691.  
  1692.   shell = (GtkWidget *) data;
  1693.   gimp_dialog_hide (shell);
  1694. }
  1695.  
  1696. static void
  1697. tool_options_reset_callback (GtkWidget *widget,
  1698.                  gpointer   data)
  1699. {
  1700.   GtkWidget *shell;
  1701.  
  1702.   shell = (GtkWidget *) data;
  1703.  
  1704.   if (!active_tool)
  1705.     return;
  1706.  
  1707.   if (tool_info[(gint) active_tool->type].tool_options->reset_func)
  1708.     (* tool_info[(gint) active_tool->type].tool_options->reset_func) ();
  1709. }
  1710.  
  1711. gchar *
  1712. tool_active_PDB_string (void)
  1713. {
  1714.   gchar *toolStr = "gimp_paintbrush_default";
  1715.  
  1716.   /*  Return the correct PDB function for the active tool
  1717.    *  The default is paintbrush if the tool is not recognised
  1718.    */
  1719.  
  1720.   if (!active_tool)
  1721.     return toolStr;
  1722.  
  1723.   switch (gimp_context_get_tool (gimp_context_get_user ()))
  1724.     {
  1725.     case PENCIL:
  1726.       toolStr = "gimp_pencil";
  1727.       break;
  1728.     case PAINTBRUSH:
  1729.       toolStr = "gimp_paintbrush_default";
  1730.       break;
  1731.     case ERASER:
  1732.       toolStr = "gimp_eraser_default";
  1733.       break;
  1734.     case AIRBRUSH:
  1735.       toolStr = "gimp_airbrush_default";
  1736.       break;
  1737.     case CLONE:
  1738.       toolStr = "gimp_clone_default";
  1739.       break;
  1740.     case CONVOLVE:
  1741.       toolStr = "gimp_convolve_default";
  1742.       break;
  1743.     case SMUDGE:
  1744.       toolStr = "gimp_smudge_default";
  1745.       break;
  1746.     case DODGEBURN:
  1747.       toolStr = "gimp_dodgeburn_default";
  1748.       break;
  1749.     default:
  1750.       break;
  1751.     }
  1752.  
  1753.   return toolStr;
  1754. }
  1755.  
  1756. GdkPixmap *
  1757. tool_get_pixmap (ToolType type)
  1758. {
  1759.   return (tool_info[type].icon_pixmap);
  1760. }
  1761.  
  1762. GdkPixmap *
  1763. tool_get_mask (ToolType type)
  1764. {
  1765.   return (tool_info[type].icon_mask);
  1766. }
  1767.